﻿// 适用于下拉菜单，注意需要样式表的配合，注意放置顺序，只能放在 menu 的后面，如果先加载 js 会出现找不到 menu 的情况
function menuFix() 
{
	var sfEls = document.getElementById("menu").getElementsByTagName("li");
	
	for (var i = 0; i < sfEls.length; i++) 
	{
		sfEls[i].onmouseover=function() 
		{
			this.className+=(this.className.length > 0 ? " ": "") + "sfhover";
			// 解决IE7的兼容问题
			if(window.event)
			{
				var ul = this.getElementsByTagName("ul")[0];
				if(ul) ul.style.left = "auto";
			}
		}
		
		sfEls[i].onmousedown=function() 
		{
			this.className+=(this.className.length > 0 ? " ": "") + "sfhover";
		}
		
		sfEls[i].onmouseup=function() 
		{
			this.className+=(this.className.length > 0 ? " ": "") + "sfhover";
		}
		
		sfEls[i].onmouseout=function() 
		{
			this.className=this.className.replace(new RegExp("( ?|^)sfhover\\b"), "");
			// 解决IE7的兼容问题
			if(window.event)
			{
				var to = event.toElement;
				var ul = this.getElementsByTagName("ul")[0];
				if(ul) if(!ul.contains(to)) ul.style.left = "-999em";
			}
		}
	}
}
// window.onload=menuFix;
menuFix();